package com.wby.store.ware.service.impl;

import com.wby.store.ware.service.TestService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class TestServiceImpl implements TestService {
    public List<Integer> list = Collections.synchronizedList(new ArrayList<Integer>());

    @Override
    public synchronized   boolean test(Integer x) {
        boolean absent = !list.contains(x);
        if (absent) {
            list.add(x);
            System.out.println(Thread.currentThread().getName()+" ::"+absent + " 数据是:"+list.toString());
        }
        return absent;
    }
}
